<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
            <div style="margin: 10px 10px 10px 10px">
                <div class="layui-form-item" style="display: flex">
                        <div style="font-size: 20px;">今日金币比例：</div>
                        <div style="font-size:20px;color:#0b76ac;padding-top:0.3%;">{$todayRatio}%</div>
                </div>
            </div>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
{include file="public/footer" /}

<script>
    layui.use(['form', 'table'], function () {
        let $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/admin/Ratio/index?action=ajax',
            method: 'post',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter',],
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.data.total, //解析数据长度
                    "data": res.data.data, //解析数据列表
                };
            },
            cols: [[
                {field: 'ratio', title: '比例',templet: function(d){
                    return parseFloat(d.ratio*100).toFixed(0)+'%'
                    }},
                {field: 'apply_time', title: '开始时间', sort: true},
                {title: '操作', toolbar: '#currentTableBar', minWidth: 120}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            page: false,
            skin: 'line'
        });
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {

            if (obj.event === 'add') {
                let index = layer.open({
                    title: '添加金币比例',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/Ratio/ratio_add',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });



        table.on('tool(currentTableFilter)', function (obj) {
            let data = obj.data;
            if (obj.event === 'edit') {
                let index = layer.open({
                    title: '编辑行业',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/Ratio/ratio_write?id='+obj.data.id,
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            }
            else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    delajax(data.id,function (data) {
                        if (data.status) {
                            layer.msg('删除成功!', {icon: 1, time: 1000});
                            location.reload();
                        }else{
                            layer.msg(data.msg, {
                                icon: 2,
                                time: 3000
                            });
                        }
                    })
                });
            }
        });

        function delajax(ids,callback) {

            $.ajax({
                url: '/admin/Ratio/ratio_del',
                type: 'post',
                dataType: 'json',
                data: {
                    id: ids,
                },
                success: function(data) {
                    callback(data)
                },
                error: function(re) {
                }
            });
        }
    });

</script>



</body>
</html>